package cn.school.demo.ui.point_ranking

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import cn.school.demo.MyApplication
import cn.school.demo.pojo.Leaderboard
import cn.school.demo.pojo.User
import cn.school.demo.repository.IntegralDetailsRepository
import com.blankj.utilcode.util.LogUtils

class PointRankingViewModel : ViewModel() {
    private val _userList = mutableListOf<User>()
    val userList: MutableList<User> get() = _userList

    private val _leaderboard = MutableLiveData<Leaderboard>()
    val leaderboard: LiveData<Leaderboard> get() = _leaderboard

    private val _leaderboardTwo = MutableLiveData<Leaderboard>()
    val leaderboardByUser: LiveData<Leaderboard> get() = _leaderboardTwo

    private val _userListTwo = mutableListOf<User>()
    val userListByUser: MutableList<User> get() = _userListTwo

    private var _click = 0
    val click: Int get() = _click

    fun setLeaderboard(leaderboard: Leaderboard) {
        _leaderboard.value = leaderboard
    }
    fun setLeaderboardTwo(leaderboard: Leaderboard) {
        _leaderboardTwo.value = leaderboard
    }

    fun setClick(c: Int){
        _click = c
    }

    fun updateUserList(list: MutableList<User>) {
        LogUtils.e(list.size)
        _userList.clear()
        _userList.addAll(list)
        LogUtils.e(_userList.size)
    }

    fun updateUserListTwo(list: MutableList<User>) {
        LogUtils.e(list.size)
        _userListTwo.clear()
        _userListTwo.addAll(list)
        LogUtils.e(_userListTwo.size)
    }

    fun getTotalIntegralRanking(): LiveData<MutableMap<String, Any>> =
        IntegralDetailsRepository().getTotalIntegralRanking(MyApplication.user!!.sfNumber)

    fun getYearIntegralRanking(): LiveData<MutableMap<String, Any>> =
        IntegralDetailsRepository().getYearIntegralRanking(MyApplication.user!!.sfNumber)
}